<!DOCTYPE html>
<html lang="en">

<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">包邮书籍列表</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-2">
                <a class="btn btn-block btn-primary" href="{:U('Book/index')}?BY=1" target="_blank">添加包邮书籍</a>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                             id="all_checkbox"></th>
                                        <th style="text-align:center" width="12%">条形码</th>
                                        <th style="text-align:center">图片</th>
                                        <th style="text-align:center" width="30%">书名</th>
                                        <th style="text-align:center">作者</th>
                                        <th style="text-align:center">出版社</th>
                                        <th style="text-align:center" width="10%">书籍包装</th>
                                        <th style="text-align:center" width="5%">排序</th>
                                        <th style="text-align:center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="DATA" item="v" key="k">
                                        <tr class="odd gradeX">
                                            <td><input name="checkbox" type='checkbox' value="{$v.ID}"></td>
                                            <td>{$v.ISBN}</td>
                                            <td><img src="{$v.PIC_URL}" width="80px"></td>
                                            <td>{$v.TITLE}</td>
                                            <td>{$v.AUTHOR}</td>
                                            <td>{$v.PRESS}</td>
                                            <td>{$v.PACKING_SPECIFICATION}</td>
                                            <td onclick="add('{$v.ID}' ,$(this))" >{$v.SORT}</td>
                                            <td><a class="btn  btn-primary" onclick="del('{$v.by_book_id}',$(this))">移除包邮名单</a></td>
                                        </tr>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                    </div>
                </div>


            </div>
        </div>

    </div>
</div>

<!--修改书籍排序号-->
<div id="changesort" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">修改书籍排序号</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <input id="order_id" type="hidden" name="order_id" value="">

                        <div class="col-xs-12">
                            <label>序号</label>
                            <input id="sortnum" name="sortnum" class="rugby-login form-control" value="">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button onclick="updatecost()">
                    确认
                </button>
            </div>
        </div>
    </div>
</div>
<!--修改书籍排序号-->

<include file="CommonSidebar:common-script"/>
<script src="__ROOT__/Application/Admin/Public/js/jquery.datetimepicker.js"></script>
<!-- DataTables JavaScript -->
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->


<script type="text/javascript" src="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.js?v=3"></script>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.css" type="text/css"
      media="screen"/>


<script>
    $(document).ready(function () {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>
<script>

    //修改排序弹窗
    var elem_all;
    function add(ID, elem) {
        elem_all = elem;
        $("#order_id").val(ID);
        $("#sortnum").val(elem.html());
        $("#changesort").modal("show");
    }
    //修改排序操作
    function updatecost() {
        var ID = $("#order_id").val();
        var sortnum = $("#sortnum").val();

        if (confirm("确认修改？")) {
            $.post("{:U('Book/updatesort')}",
                    {ID: ID, sortnum: sortnum},
                    function (data) {
                        console.log(data);
                        if (parseInt(data) == 1) {
                            alert('修改成功');
                            elem_all.html(sortnum);
                        } else {
                            alert('修改失败');
                        }
                    });
            $("#changesort").modal("hide");
        }
    }


    $("#all_checkbox").click(function () {
        if ($(this).is(':checked')) {
            $("input[name='checkbox']").prop("checked", "true");
        } else {
            $("input[name='checkbox']").removeAttr("checked", false);

        }
    })

    function Del() {
        var vals = [];
        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
            vals.push($(this).val());
            $(this).hide();
        });
        if (vals.length <= 0) {
            alert('请选择书籍');
            return 0;
        }
        $.post("{:U('Basket/Del')}",
                {IDS: vals},
                function (data) {
                    console.log(data);
                    if (parseInt(data)) {
                        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
                            $(this).hide();
                        });
                        alert('移除书籍成功');
                    } else {
                        alert('移除书籍失败');
                    }

                });
    }

    function updateSTOCK(ID, elem, top) {
        $.post("{:U('Book/updateSTOCK')}",
                {ID: ID, top: top},
                function (data) {
                    if (parseInt(data) >= 0) {
                        if (top == 1) {
                            elem.next().html(data);
                        } else {
                            elem.prev().html(data);
                        }
                    } else {
                        alert('修改失败,库存不能小于0');
                        window.location.reload()
                    }
                });
    }

    function del(ID, $elem) {
        if (confirm("确认删除？")) {
            $.post("{:U('deleteByBook')}",
                    {ID: ID},
                    function (data) {
                        if (parseInt(data) == 1) {
                            $elem.parent().parent().remove();
                            alert('删除成功');
                        } else {
                            alert('删除失败');
                        }
                    });
        }
    }
</script>
</body>

</html>
